/*
 * @Author       : 乐乐侠在此
 * @Date         : 2024-02-20 09:23:58
 * @LastEditors  : Please set LastEditors
 * @LastEditTime : 2024-02-20 09:35:38
 * @Description  : 饿汉模式
 */
#include <iostream>
using namespace std;

class Singleton {
public:
    static Singleton& getInstance() {
        return instance;
    }

    // 删除拷贝构造函数和拷贝赋值操作符，确保单例不被拷贝
    Singleton(const Singleton&) = delete;
    Singleton& operator=(const Singleton&) = delete;

private:
    static Singleton instance;
    static void show(){cout<<"show"<<endl;};
    Singleton() {}
};

Singleton Singleton::instance; // 在程序启动时就创建单例实例

int main() {
    Singleton& instance1 = Singleton::getInstance();
    Singleton& instance2 = Singleton::getInstance();

    //Singleton::show();
    // instance1 和 instance2 是同一个实例
    if (&instance1 == &instance2) {
        std::cout << "Same instance" << std::endl;
    } else {
        std::cout << "Different instances" << std::endl;
    }

    return 0;
}
